﻿Public Class GEstTVA

    Dim macnx As New PPE3.ClassMySqlConnect("853339_depanneur", "071064")

#Region "Lancement du formulaire"

    Private Sub GEstTVA_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = FrmStart
        Me.Left = 0
        Me.Top = 0

        macnx.Se_Connecter_MySqlServer()
        dgGTVA.DataSource = Nothing
        macnx.viderVue("Touttva")
        dgGTVA.DataSource = macnx.Executer_Requete_Select("select idCalcule,CoefInferieur,Multiplie from Calcule order by multiplie asc", "Touttva")

        DataGridView1.DataSource = Nothing
        macnx.viderVue("Tout")
        DataGridView1.DataSource = macnx.Executer_Requete_Select("select idtva,TVA from tva where idtva=1", "Tout")

        macnx.Se_Deconnecter_MySqlServer()
    End Sub


#End Region

#Region "Bouton"

#Region "GESTION TVA"

    '------------------------GESTION TVA----------------------------'
#Region "BOUTON MODIFIER"

    Private Sub BtnModifTVA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModifTVA.Click
        Dim id As Integer = 1
        If BtnModifTVA.Text = "Modifier" Then

            txtTVA.Enabled = True

            txtTVA.Text = ""

            MessageBox.Show("Attention ! ,Veuillez remplire le champ TVA pour la modifier !", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            BtnModifTVA.Text = "Valider!"
        Else
            If txtTVA.Text <> "" Then


                Dim b As String

                Dim reponse = MessageBox.Show("La TVA va être MODIFIER.., Confirmez-vous?!", "MODIFICATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information)


                b = txtTVA.Text


                If reponse = vbYes Then

                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action("UPDATE tva Set TVA='" & b & "' where idTVA = '" & id & "'")
                    macnx.Se_Deconnecter_MySqlServer()


                    rafraichir()

                    txtTVA.Enabled = False
                    txtTVA.Text = ""
                    BtnModifTVA.Text = "Modifier"

                Else

                    txtTVA.Text = ""
                    BtnModifTVA.Text = "Modifier"
                    txtTVA.Enabled = False
                End If
            End If
        End If

    End Sub
#End Region

#End Region

#Region "GESTION COEFFICIENT"

    '---------------------GESTION COEFFICIENT-----------------------'
#Region "BOUTON MODIFIER"
    Private Sub BtnModifCoef_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModifCoef.Click
        If BtnModifCoef.Text = "Modifier" Then
            TxtCoefInf.Enabled = True
            TxtMultiplie.Enabled = True
            TxtCoefInf.Text = ""
            TxtMultiplie.Text = ""

            MessageBox.Show("Attention ! ,Veuillez remplire les champ  pour modifier !", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            BtnModifCoef.Text = "Valider!"
        Else
            If TxtIDCoef.Text <> "" Then

                Dim reponse = MessageBox.Show("Les coef  vont être MODIFIER.., Confirmez-vous?!", "MODIFICATION", MessageBoxButtons.YesNo, MessageBoxIcon.Information)

                If reponse = vbYes Then

                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action(" UPDATE calcule Set CoefInferieur='" & TxtCoefInf.Text & "',multiplie='" & TxtMultiplie.Text & "'  where idCalcule = " & TxtIDCoef.Text & "")
                    macnx.Se_Deconnecter_MySqlServer()


                    rafraichir()

                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    TxtIDCoef.Text = ""
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    BtnModifCoef.Text = "Modifier"

                Else
                    TxtIDCoef.Text = ""
                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    BtnModifCoef.Text = "Modifier"

                End If
            End If
        End If
    End Sub
#End Region

#Region "BOUTON SUPPRIMER"

    Private Sub BtnAjoutSup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAjoutSup.Click
        Dim position As Integer


        If BtnAjoutSup.Text = "Supprimer" Then
            TxtCoefInf.Enabled = True

            TxtMultiplie.Enabled = True


            TxtCoefInf.Text = ""
            TxtMultiplie.Text = ""

            MessageBox.Show("Attention ! , Pour supprimer un matériel veuillez sélectionnez la ligne correspondant à celui-ci !", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

            BtnAjoutSup.Text = "Valider!"
            BtnModifCoef.Enabled = False
            BtnAjoutCoef.Enabled = False
        Else
            If TxtIDCoef.Text <> "" Then
                Dim nu As Integer
                nu = TxtIDCoef.Text

                Dim reponse = MessageBox.Show("Le matériel va être SUPPRIMER, confirmez vous cet suppression...?!", "SUPPRESSION", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)

                If reponse = vbOK Then

                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action("Delete from calcule Where idcalcule= " & nu & "")
                    macnx.Se_Deconnecter_MySqlServer()

                    position = 0

                    rafraichir()

                    BtnAjoutSup.Text = "Supprimer"
                    TxtIDCoef.Text = ""
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    BtnModifCoef.Enabled = False
                    BtnAjoutCoef.Enabled = False
                Else
                    TxtIDCoef.Text = ""
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    BtnModifCoef.Enabled = True
                    BtnAjoutCoef.Enabled = True
                    BtnAjoutSup.Text = "Supprimer"
                End If

            End If
        End If
    End Sub

#End Region

#Region "BOUTON AJOUTER"
    Private Sub BtnAjoutCoef_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAjoutCoef.Click

        Dim position As Integer

        If BtnAjoutCoef.Text = "Ajouter" Then

            macnx.Se_Connecter_MySqlServer()

            macnx.Generer_Cle_Primaire("idcalcule", "calcule")

            macnx.Se_Deconnecter_MySqlServer()

            TxtCoefInf.Enabled = True
            TxtMultiplie.Enabled = True
            TxtCoefInf.Text = ""
            TxtMultiplie.Text = ""
            MessageBox.Show("Attention ! , Pour ajouter un coef veuillez remplir tous les champs !", "ATTENTION", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            BtnAjoutCoef.Text = "Valider!"
            BtnModifCoef.Enabled = False
            BtnAjoutSup.Enabled = False
        Else
            Dim reponse = MessageBox.Show("Vous êtes sur le point d'ajouter un nouveau coefficient, en êtes vous bien sur ...?!", "Insertion", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
            If reponse = vbOK Then
                If TxtIDCoef.Text <> "" Then
                    Dim a As Integer
                    Dim b As String
                    Dim c As String

                    a = CInt(TxtIDCoef.Text)
                    b = TxtCoefInf.Text.ToString
                    c = TxtMultiplie.Text

                    macnx.Se_Connecter_MySqlServer()
                    macnx.Executer_Requete_Action("INSERT INTO calcule VALUES ( " & a & ", '" & b & "','" & c & "' )")
                    macnx.Se_Deconnecter_MySqlServer()

                    position = 0

                    rafraichir()
                    TxtIDCoef.Text = ""
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    BtnAjoutCoef.Text = "Ajouter"
                    BtnModifCoef.Enabled = True
                    BtnAjoutSup.Enabled = True
                Else
                    TxtCoefInf.Text = ""
                    TxtMultiplie.Text = ""
                    TxtCoefInf.Enabled = False
                    TxtMultiplie.Enabled = False
                    MessageBox.Show("Erreur de saisie...!", "   ALERTE!", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                TxtIDCoef.Text = ""
                TxtCoefInf.Text = ""
                TxtMultiplie.Text = ""
                TxtCoefInf.Enabled = False
                TxtMultiplie.Enabled = False
                BtnAjoutCoef.Text = "Ajouter"
            End If
        End If
    End Sub

#End Region
#End Region

#End Region

#Region "UTILE"
    Private Sub rafraichir()

        macnx.Se_Connecter_MySqlServer()


        dgGTVA.DataSource = Nothing
        dgGTVA.DataSource = macnx.Executer_Requete_Select("select idCalcule,CoefInferieur,Multiplie from calcule", "Touttva")


        DataGridView1.DataSource = Nothing

        DataGridView1.DataSource = macnx.Executer_Requete_Select("select idTVA,TVA from tva where idTVA=1", "Tout")
        macnx.Se_Deconnecter_MySqlServer()


    End Sub

    Private Sub GEstTVA_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        macnx.Se_Connecter_MySqlServer()
        macnx.viderVue("Touttva")
        macnx.viderVue("Tout")
        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    Private Sub dgGTVA_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgGTVA.CellClick

        If dgGTVA.CurrentCell.Value Is DBNull.Value Then
            TxtIDCoef.Enabled = False

        Else

            TxtIDCoef.Text = dgGTVA.CurrentRow.Cells(0).Value()
            TxtCoefInf.Text = dgGTVA.CurrentRow.Cells(1).Value()
            TxtMultiplie.Text = dgGTVA.CurrentRow.Cells(2).Value()

        End If

    End Sub


    Private Sub TxtMultiplie_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtMultiplie.TextChanged
        macnx.Se_Connecter_MySqlServer()
        If TxtMultiplie.Text = "" Then
            Me.ValidProvider.SetError(Me.TxtMultiplie, "")
            Me.ErrorProvider1.SetError(Me.TxtMultiplie, "")
            BtnAjoutCoef.Enabled = True
            BtnModifCoef.Enabled = True
            BtnAjoutSup.Enabled = True
        Else
            If macnx.YESCHIFFRE(TxtMultiplie.Text) = False Then
                Me.ErrorProvider1.SetError(Me.TxtMultiplie, " Saisie,Fausse Seulement des chiffre  !!!")
                Me.ValidProvider.SetError(Me.TxtMultiplie, "")
                BtnAjoutCoef.Enabled = False
                BtnModifCoef.Enabled = False
                BtnAjoutSup.Enabled = False
            Else
                Me.ErrorProvider1.SetError(Me.TxtMultiplie, "")
                Me.ValidProvider.SetError(Me.TxtMultiplie, "Saisie juste")
                BtnAjoutCoef.Enabled = True
                BtnModifCoef.Enabled = True
                BtnAjoutSup.Enabled = True
            End If
        End If
        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    Private Sub TxtCoefInf_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtCoefInf.TextChanged
        macnx.Se_Connecter_MySqlServer()

        If TxtCoefInf.Text = "" Then
            Me.ValidProvider.SetError(Me.TxtCoefInf, "")
            Me.ErrorProvider1.SetError(Me.TxtCoefInf, "")
            BtnAjoutCoef.Enabled = True
            BtnModifCoef.Enabled = True
            BtnAjoutSup.Enabled = True
        Else
            If macnx.YESCHIFFRE(TxtCoefInf.Text) = False Then
                Me.ErrorProvider1.SetError(Me.TxtCoefInf, " Saisie,Fausse Seulement des chiffre  !!!")
                Me.ValidProvider.SetError(Me.TxtCoefInf, "")
                BtnAjoutCoef.Enabled = False
                BtnModifCoef.Enabled = False
                BtnAjoutSup.Enabled = False
            Else
                Me.ErrorProvider1.SetError(Me.TxtCoefInf, "")
                Me.ValidProvider.SetError(Me.TxtCoefInf, "Saisie juste")
                BtnAjoutCoef.Enabled = True
                BtnModifCoef.Enabled = True
                BtnAjoutSup.Enabled = True
            End If
        End If
        macnx.Se_Deconnecter_MySqlServer()
    End Sub

    Private Sub txtTVA_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTVA.TextChanged
        macnx.Se_Connecter_MySqlServer()
        If txtTVA.Text = "" Then
            Me.ValidProvider.SetError(Me.txtTVA, "")
            Me.ErrorProvider1.SetError(Me.txtTVA, "")
            BtnModifTVA.Enabled = True

        Else
            If macnx.YESCHIFFRE(txtTVA.Text) = False Then
                Me.ErrorProvider1.SetError(Me.txtTVA, " Saisie,Fausse Seulement des chiffre  !!!")
                Me.ValidProvider.SetError(Me.txtTVA, "")
                BtnModifTVA.Enabled = False

            Else
                Me.ErrorProvider1.SetError(Me.txtTVA, "")
                Me.ValidProvider.SetError(Me.txtTVA, "Saisie juste")
                BtnModifTVA.Enabled = True
            End If
        End If
        macnx.Se_Deconnecter_MySqlServer()

    End Sub

    Private Sub TxtIDCoef_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtIDCoef.TextChanged
        macnx.Se_Connecter_MySqlServer()
        If TxtIDCoef.Text = "" Then
            Me.ValidProvider.SetError(Me.TxtIDCoef, "")
            Me.ErrorProvider1.SetError(Me.TxtIDCoef, "")
            BtnAjoutCoef.Enabled = True
            BtnModifCoef.Enabled = True
            BtnAjoutSup.Enabled = True
        Else
            If macnx.YESCHIFFRE(TxtIDCoef.Text) = False Then
                Me.ErrorProvider1.SetError(Me.TxtIDCoef, " Saisie,Fausse Seulement des chiffre  !!!")
                Me.ValidProvider.SetError(Me.TxtIDCoef, "")
                BtnAjoutCoef.Enabled = False
                BtnModifCoef.Enabled = False
                BtnAjoutSup.Enabled = False
            Else
                Me.ErrorProvider1.SetError(Me.TxtIDCoef, "")
                Me.ValidProvider.SetError(Me.TxtIDCoef, "Saisie juste")
                BtnAjoutCoef.Enabled = True
                BtnModifCoef.Enabled = True
                BtnAjoutSup.Enabled = True
            End If
        End If
        macnx.Se_Deconnecter_MySqlServer()
    End Sub

#End Region




End Class